<?php
/**
 * Created by PhpStorm.
 * User: geolo
 * Date: 2018/11/21
 * Time: 15:07
 */
namespace  app\modules\mch\controllers;
use app\models\Super;
use app\modules\mch\models\SuperForm;

class  SuperController extends Controller
{
    public function actionIndex(){
        $store_id = $this->store->id;
        $form = new SuperForm();
        if(\yii::$app->request->ispost){
            $model = Super::findOne(['store_id'=>$store_id]);
            if(!$model){
                $model = new Super();
            }
            $form->model = $model;
            $form->attributes = \yii::$app->request->post();
            $form->store_id = $store_id;
            return $this->renderJson($form->save(),JSON_UNESCAPED_UNICODE);
        }
        $data = Super::findOne(['store_id'=>$store_id]);
        return $this->render('index',['data'=>$data]);
    }
}